package com.ptswitch.material.model.contract;

import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.validation.constraints.Size;

import org.apache.tapestry5.beaneditor.DataType;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hxzon.project.BaseEntity;
import org.hxzon.tapestry5.util.TapestryEx;
import org.hxzon.util.BigDecimalUtil;

import com.ptswitch.material.model.common.Uzer;

@Entity
public class ContractPayment extends BaseEntity {
    public static final int Askfor_Payment = 1;
    public static final int Reply_Payment = 2;

    private static final long serialVersionUID = -7485172456471455798L;

    @ManyToOne
    @JoinColumn(name = "contractCode", referencedColumnName = "code", insertable = false, updatable = false)
    private Contract contract;

    @Column(columnDefinition = DefineVarchar32)
    @Size(max = DefineSize32)
    private String contractCode;

    @OneToOne(fetch = FetchType.EAGER)
    @NotFound(action = NotFoundAction.IGNORE)
    private ContractPayment asker;

    private boolean refund;//退款

    @DataType(TapestryEx.DataType_currency)
    private BigDecimal payment = BigDecimalUtil.Int0;

    @ManyToOne(fetch = FetchType.EAGER)
    private Uzer sender;

    @ManyToOne(fetch = FetchType.EAGER)
    private Uzer reciever;

    @Column(columnDefinition = DefineVarchar2048)
    @Size(max = DefineSize2048)
    private String remark;

    private int paymentType;

    // set and get

    public Contract getContract() {
        return contract;
    }

    public void setContract(Contract contract) {
        this.contract = contract;
        this.contractCode = contract.getCode();
    }

    public String getContractCode() {
        return contractCode;
    }

    public void setContractCode(String contractCode) {
        this.contractCode = contractCode;
    }

    public ContractPayment getAsker() {
        return asker;
    }

    public void setAsker(ContractPayment asker) {
        this.asker = asker;
    }

    public BigDecimal getPayment() {
        return payment;
    }

    public void setPayment(BigDecimal payment) {
        this.payment = payment;
    }

    public boolean isRefund() {
        return refund;
    }

    public void setRefund(boolean refund) {
        this.refund = refund;
    }

    public Uzer getSender() {
        return sender;
    }

    public void setSender(Uzer sender) {
        this.sender = sender;
    }

    public Uzer getReciever() {
        return reciever;
    }

    public void setReciever(Uzer reciever) {
        this.reciever = reciever;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public int getPaymentType() {
        return paymentType;
    }

    public void setPaymentType(int type) {
        this.paymentType = type;
    }

    //----transient for form-----------------
    private transient BigDecimal paymentCurrentMax;
    private transient BigDecimal paymentCurrent;

    public BigDecimal getPaymentCurrentMax() {
        return paymentCurrentMax;
    }

    public void setPaymentCurrentMax(BigDecimal paymentCurrentMax) {
        this.paymentCurrentMax = paymentCurrentMax;
    }

    public BigDecimal getPaymentCurrent() {
        return paymentCurrent;
    }

    public void setPaymentCurrent(BigDecimal paymentCurrent) {
        this.paymentCurrent = paymentCurrent;
    }

}
